<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view">
    <div class="product-essential">
	 <div class="product-name">
			<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
			<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
	</div>
    <form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>

        <div class="product-shop">
            <?php if($_product->isSaleable()): ?>
			    <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
			<?php else: ?>
			    <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Ships in 2-3 Weeks') ?></span></p>
			<?php endif; ?>
            <?php if ($this->canEmailToFriend()): ?>
                <p class="email-friend"><a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a></p>
            <?php endif; ?>

            <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
            <?php echo $this->getChildHtml('alert_urls') ?>
            <?php echo $this->getChildHtml('product_type_data') ?>
            <?php echo $this->getTierPriceHtml() ?>
            <?php echo $this->getChildHtml('extrahint') ?>

            <?php if (!$this->hasOptions()):?>
                <div class="add-to-box">
                    
                        <?php echo $this->getChildHtml('addtocart') ?>
                        <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                            <span class="or"><?php echo $this->__('OR') ?></span>
                        <?php endif; ?>
                    
                    <?php echo $this->getChildHtml('addto') ?>
                </div>
                <?php echo $this->getChildHtml('extra_buttons') ?>
            <?php endif; ?>


            <?php echo $this->getChildHtml('other');?>

            <?php if ($this->hasOptions()):?>
                <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
            <?php endif;?>
			<?php if ($_product->getShortDescription()):?>
                <div class="short-description">
                    <h2><?php echo $this->__('Quick Overview') ?></h2>
                    <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
                </div>
            <?php endif;?>
			<div class="addthis_toolbox addthis_default_style">
					<a href=http://www.addthis.com/bookmark.php?username=mycode class="addthis_button_compact">Share</a>
					<span class="addthis_separator">|</span>
					<a class="addthis_button_preferred_1"></a>
					<a class="addthis_button_preferred_2"></a>
					<a class="addthis_button_preferred_3"></a>
					<a class="addthis_button_preferred_4"></a>
					<a class="addthis_button_preferred_5"></a>
					<a class="addthis_button_preferred_6"></a>
					</div>

					<script type="text/javascript" src="http://s7.addthis.com/js/250/
						addthis_widget.js#username=mycode"></script>
        </div>

        <div class="product-img-box">
            <?php echo $this->getChildHtml('media') ?>



        </div>
<?php

$status = Mage::getSingleton('importplus/status');
//$_attributeCode = 'diamond_size';
$_attributeCode = $status->getAttributeCode();

$eavAttributeModel = Mage::getModel('eav/entity_attribute');
$attribute_id = $eavAttributeModel->getIdByCode('catalog_product',$_attributeCode);
$target = false;
$content = '';

if ( $this->getProduct()->gettype_id() == 'configurable') {
    $_product  = Mage::getModel('catalog/product')->load($this->getProduct()->getId());
    $_attributes = Mage::helper('core')->decorateArray(
        $this->getProduct()->getTypeInstance(true)->getConfigurableAttributes($_product)
    );

    $products = array();
    $allProducts = $this->getProduct()->getTypeInstance(true)
        ->getUsedProducts(null, $this->getProduct());
    foreach ($allProducts as $product) {
        
            $products[] = $product;
        
    }

    $bk = Mage::registry('product');
    foreach ($products as $product) {
        $alias = 'additional' ;
        Mage::unregister('product');
        Mage::register('product',$product);
        $html = $this->getLayout()->createBlock('catalog/product_view_attributes')->setTemplate('catalog/product/view/attributes.phtml');
        $content .= "\n<div class='product-tabs-content'>";
        $content .= '<div class="product_c_options product_'.$product->getId().'" style=" display: none; ">';
        $content .= $html->toHtml();
        $content .= '</div></div>';

    }
    Mage::unregister('product');
    Mage::register('product',$bk);
}
$menu = '';
$out = '';
$first = true;
$end = true;
$info = array();

foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html){
    $title = $this->getChildData($alias, 'title');
    $info[$alias] = array('title' => $title, 'html'=>$html);
}

if (isset($info['additional'])){
    $alias = 'additional';
    $menu .= "<li id='product_tabs_{$alias}' class='active first'><a href='#'>Additional Information</a></li>";
    $out .= "<div class='product-tabs-content' id='product_tabs_{$alias}_contents'>";
    if ($_attributeCode == 'diamond_size' && $content) {
        $out .= $content;
    } else {
        $out .= $info['additional']['html'];
    }
    $out .= '</div>';
    unset($info['additional']);
}

if (isset($info['description'])){
    $alias = 'description';
    $menu .= "<li id='product_tabs_{$alias}' class=''><a href='#'>Product Description</a></li>";
    
$out .= "<div class='product-tabs-content' id='product_tabs_{$alias}_contents'>";

    $out .= $info['description']['html'];
    $out .= '</div>';

    unset($info['description']);

}

$count = count($info);
foreach($info as $alias => $item) {
    $count--;
    if ($title = $item['title']){
        $menu .= "<li id='product_tabs_{$title}' class='". !$count ? ' last':''."'><a href='#'>{$title}</a></li>";
    } else {
        $menu .= "<li id='product_tabs_{$title}' class='". !$count ? ' last':''."'><a href='#'>{$title}</a></li>";
    }

    $out .= "<div class='product-tabs-content' id='product_tabs_{$alias}_contents'>";
    $out .= $item['html'];
    $out .= '</div>';
}

?>

    



</div>

        <div class="clearer"></div>

    </form>
    <script type="text/javascript">
    //<![CDATA[
            var productAddToCartForm = new VarienForm('product_addtocart_form');
            productAddToCartForm.submit = function(){
                    if (this.validator.validate()) {
                            this.form.submit();
                    }
            }.bind(productAddToCartForm);
    //]]>
    </script>
    </div>

       <div class="product-collateral">
        <ul class="product-tabs">
           
        </ul>
        <?php echo $out; ?>
<script type="text/javascript">
//<![CDATA[
Varien.Tabs = Class.create();
Varien.Tabs.prototype = {
  initialize: function(selector) {
    var self=this;
    $$(selector+' a').each(this.initTab.bind(this));
  },

  initTab: function(el) {
      el.href = 'javascript:void(0)';
      if ($(el.parentNode).hasClassName('active')) {
        this.showContent(el);
      }
      el.observe('click', this.showContent.bind(this, el));
  },

  showContent: function(a) {
    var li = $(a.parentNode), ul = $(li.parentNode);
    ul.select('li', 'ol').each(function(el){
      var contents = $(el.id+'_contents');
      if (el==li) {
        el.addClassName('active');
        contents.show();
      } else {
        el.removeClassName('active');
        contents.hide();
      }
    });
  }
}
new Varien.Tabs('.product-tabs');
//]]>
</script>
    </div> 
</div>
</div>

